package com.cjh.task;

import com.cjh.utils.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * <p>
 *  定时任务
 * </p>
 *
 * @author cjh
 * @date 2021/2/3 15:24
 */
@Component("scheduled")
public class Scheduled {

    @Autowired
    private RedisUtil redisUtil;

    private static Logger logger = LoggerFactory.getLogger(Scheduled.class);

    /**
     * 每n秒执行一次定时任务，解决redis几分钟不访问就报异常的问题
     */
    @org.springframework.scheduling.annotation.Scheduled(cron = "0/10 * * * * ?")
    public void myTask(){
        redisUtil.set("task","4862");
        logger.info("=>redisUtil.set()--"+new Date());
    }
}
